<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function check(){
				let username=document.getElementById("username").value
				if(username.trim()==""){//清楚前后空格
					document.getElementById("res1").innerHTML="姓名不能为空"
					return false
				}
				let password=document.getElementById("password").value
				if(password.length<6){
					document.getElementById("res2").innerHTML="密码长度不足六位"
					return false
				}
				let age=document.getElementById("age").value
				if(age<=1||age>=150||isNaN(age)){//验证是否为数字
					document.getElementById("res3").innerHTML="年龄在1岁到150之间"
					return false
				}
				let phone=document.getElementById("phone").value
				let reg = /^1\d{10}$/
				if(!reg.test(phone)){//使用正则表达式验证
					document.getElementById("res4").innerHTML="电话格式不符合规划(开头为1，总共是十一位数字)"
					return false
				}
				return true; 
			}
		</script>
	</head>
	<body>
		<form action="success.html" method="get" onsubmit="return check()">
			姓名：<input type="text" id="username"><span id="res1"></span><br>
			密码：<input type="password" id="password"><span id="res2"></span><br>
			年龄：<input type="text" id="age"><span id="res3"></span><br>
			手机：<input type="text" id="phone"><span id="res4"></span><br>
			<input type="submit" value="提交">
		</form>
	</body>
</html>
